package com.walle.concurrenttest.pattern.workthread;

import java.util.Random;

/**
 * @author zhangjiapeng
 * @Package com.walle.concurrenttest.pattern.workthread
 * @Description: ${todo}
 * @date 2019/2/22 10:54
 */
public class ClientThread extends Thread {

    private final  Channel channel;
    private Random random = new Random();

    public ClientThread(String name, Channel channel) {
        super(name);
        this.channel = channel;
    }

    @Override
    public void run() {
        int i = 0;
        while (i < 10 ){
            Request request = new Request(getName(),i);
            System.out.println(String.format("%s put  No.%d Request",getName(),i));
            channel.putRequest(request);
            try {
                Thread.sleep(random.nextInt(1000));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            i++;
        }
    }
}
